﻿using System;
using System.Buffers;
using System.Linq;
using System.Text;

namespace Xc.DataAccess.PcpChannels
{
    /// <summary>
    /// 上报升级包下载状态
    /// </summary>
    public class DeviceUploadUpgradeStatusRequest : RespondFrame
    {
        public DeviceUploadUpgradeStatusRequest(byte[] dataarea) : base(dataarea)
        {

        }

        /// <summary>
        /// 要校验的数据
        /// </summary>
        /// <returns></returns>
        protected override MessageCode? ValidateMessageCode => MessageCode.UploadUpgradeStatus;
        /// <summary>
        /// 下载状态
        /// </summary>
        public DownloadStatus Status { get; set; }
        public enum DownloadStatus
        {
            Success = 0,
            /// <summary>
            /// 剩余空间不足
            /// </summary>
            SpaceInsufficient = 0x05,
            /// <summary>
            /// 下载超时
            /// </summary>
            DownloadTimeout = 0x06,
            /// <summary>
            /// 检查失败
            /// </summary>
            CheckFailed,
            /// <summary>
            /// 包不支持
            /// </summary>
            PackageNotSupport
        }

        protected override bool SetDataArea(ref SequenceReader<byte> dataArea)
        {
            if (dataArea.TryRead(out var c))
            {

                Status = (DownloadStatus)c;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
